package com.api.service.impl;

import cn.hutool.core.util.StrUtil;
import com.api.common.page.PageData;
import com.api.common.service.impl.BaseServiceImpl;
import com.api.entity.Item;
import com.api.entity.dto.ItemDTO;
import com.api.mapper.ItemMapper;
import com.api.service.ItemService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 岗位表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-08-12
 */
@Service
@AllArgsConstructor
public class ItemServiceImpl extends BaseServiceImpl<ItemMapper, Item> implements ItemService {
    @Override
    public PageData<Item> page(Map<String, Object> params) {
        IPage<Item> page = baseDao.selectPage(getPage(params,  false),
                getWrapper(params)
        );
        return getPageData(page, Item.class);
    }
    private QueryWrapper<Item> getWrapper(Map<String, Object> params) {
        String cateName = (String) params.get("cateName");
        String title = (String) params.get("title");
        QueryWrapper<Item> wrapper = new QueryWrapper<>();
        wrapper.like(StrUtil.isNotBlank(cateName), "cate_name", cateName);
        wrapper.like(StrUtil.isNotBlank(title), "title", title);
        return wrapper;
    }
}
